package com.smarthealthcare.service.impl;

import java.util.List;
import com.smarthealthcare.common.utils.DateUtils;
import com.smarthealthcare.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smarthealthcare.mapper.DoctorMapper;
import com.smarthealthcare.domain.Doctor;
import com.smarthealthcare.service.IDoctorService;
import com.smarthealthcare.doctor.mapper.IdentityMapper;

/**
 * 医生列表Service业务层处理
 * 
 * @author tuanzi
 * @date 2024-11-22
 */
@Service
public class DoctorServiceImpl implements IDoctorService 
{
    @Autowired
    private DoctorMapper doctorMapper;
    @Autowired
    private IdentityMapper identityMapper;
    @Autowired
    private DepartmentMapper departmentMapper;

    /**
     * 查询医生列表
     * 
     * @param id 医生列表主键
     * @return 医生列表
     */
    @Override
    public Doctor selectDoctorById(Long id)
    {
        Doctor doctor = doctorMapper.selectDoctorById(id);
//        doctor.setIdentity(identityMapper.selectIdentityById(doctor.getIdentityId()));
//        doctor.setDepartment(departmentMapper.selectDepartmentById(doctor.getDepartmentId()));
        return doctor;
    }

    /**
     * 查询医生列表列表
     * 
     * @param doctor 医生列表
     * @return 医生列表
     */
    @Override
    public List<Doctor> selectDoctorList(Doctor doctor)
    {
        List<Doctor> list = doctorMapper.selectDoctorList(doctor);
        for (Doctor doctor1 : list) {
            doctor1.setIdentity(identityMapper.selectIdentityById(doctor1.getIdentityId()));
            doctor1.setDepartment(departmentMapper.selectDepartmentById(doctor1.getDepartmentId()));
        }
        return list;
    }

    /**
     * 新增医生列表
     * 
     * @param doctor 医生列表
     * @return 结果
     */
    @Override
    public int insertDoctor(Doctor doctor)
    {
        doctor.setCreateTime(DateUtils.getNowDate());
        return doctorMapper.insertDoctor(doctor);
    }

    /**
     * 修改医生列表
     * 
     * @param doctor 医生列表
     * @return 结果
     */
    @Override
    public int updateDoctor(Doctor doctor)
    {
        return doctorMapper.updateDoctor(doctor);
    }

    /**
     * 批量删除医生列表
     * 
     * @param ids 需要删除的医生列表主键
     * @return 结果
     */
    @Override
    public int deleteDoctorByIds(Long[] ids)
    {
        return doctorMapper.deleteDoctorByIds(ids);
    }

    /**
     * 删除医生列表信息
     * 
     * @param id 医生列表主键
     * @return 结果
     */
    @Override
    public int deleteDoctorById(Long id)
    {
        return doctorMapper.deleteDoctorById(id);
    }

    @Override
    public Integer selectByNumber(String number) {
        return doctorMapper.selectByNumber(number);
    }
}
